package com.web.controller;

import com.core.shared.ImageUtils;
import com.service.LxfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: lxf
 * Date: 2016/7/15
 * Time: 15:01
 * To change this template use File | Settings | File Templates.
 */
@Controller
@RequestMapping("/image")
public class ImageController {

    @Autowired
    LxfService lxfService;

    @RequestMapping(value = "upload", method = RequestMethod.GET)
    public String imageUploadIndex() {
        return "front/jqueryFileUpload";
    }

    @RequestMapping(value = "upload", method = RequestMethod.POST)
    public String imageUploadIndex(MultipartFile file) {
//        ImageUtils.upload("d:\\", file);
        lxfService.upload(file);
        return "redirect:/test";
    }

    @RequestMapping(value = "ajax_upload", method = RequestMethod.GET)
    public String ajaxFileUploadIndex() {
        return "front/ajaxFileUpload";
    }

    @RequestMapping(value = "ajax_upload", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> ajaxFileUpload(MultipartFile file) {
        System.out.println("file name: " + file.getOriginalFilename());
        System.out.println("file size: " + file.getSize());
        Map<String, Object> map = new HashMap<>();
        map.put("code", "1");
        return map;
    }

}
